package com.lepu.app.usercenter.adapter;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lepu.app.usercenter.FeedBackMainActivity;
import com.lepu.app.usercenter.bean.BeanFeedbackReply;
import com.lepu.pasm.R;

public class AdapterFeedbackReply extends BaseAdapter {

	private LayoutInflater mLayoutInflater = null;
	@SuppressWarnings("unused")
	private FeedBackMainActivity mContext = null;
	private ArrayList<BeanFeedbackReply> mArrayList = null;
	private String mUserID = "";

	public AdapterFeedbackReply(FeedBackMainActivity context, ArrayList<BeanFeedbackReply> arrayList,String userID) {
		mContext = context;
		mLayoutInflater = LayoutInflater.from(context);
		mArrayList = arrayList;
		mUserID = userID;
	}

	@Override
	public int getCount() {
		int size = 0;
		if (mArrayList != null && mArrayList.size() > 0) {
			size = mArrayList.size();
		}
		return size;
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressLint("InflateParams")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		final ViewHolder holder;

		if (convertView == null) {
			convertView = mLayoutInflater.inflate(R.layout.usercenter_feedback_main_activity_listitem_reply, null);

			holder = new ViewHolder();
			
			TextView replyTimeTextView = (TextView) convertView.findViewById(R.id.replyTimeTextView);
			TextView replyContentTextView = (TextView) convertView.findViewById(R.id.replyContentTextView);
			TextView replyAskAnswerTipTextView = (TextView) convertView.findViewById(R.id.replyAskAnswerTipTextView);

			holder.replyTimeTextView = replyTimeTextView;
			holder.replyContentTextView = replyContentTextView;
			holder.replyAskAnswerTipTextView = replyAskAnswerTipTextView;
			
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		final BeanFeedbackReply item = mArrayList.get(position);
		
		//ask
		if(!TextUtils.isEmpty(item.ReplyUserID) && item.ReplyUserID.equals(mUserID)){
			holder.replyAskAnswerTipTextView.setText("  问");
			holder.replyAskAnswerTipTextView.setTextColor(Color.parseColor("#fe5e1d"));
			holder.replyTimeTextView.setText(String.format("%s", item.ReplyTime));
			holder.replyContentTextView.setText(item.ReplyContent);
		}else{
			holder.replyAskAnswerTipTextView.setText("  答");
			holder.replyAskAnswerTipTextView.setTextColor(Color.parseColor("#a6d359"));
			holder.replyTimeTextView.setText(String.format("%s", item.ReplyTime));
			holder.replyContentTextView.setText(item.ReplyContent);
		}

		return convertView;
	}

	private static class ViewHolder {
		TextView replyTimeTextView;
		TextView replyContentTextView;
		TextView replyAskAnswerTipTextView;
	}
}
